using System;
using System.Security.Cryptography;
using System.Text;

namespace CloudApiServer;

public class TripleDesCryptoHelper
{
    public static string DecryptInitInfo(string encryptedBase64, string base64Key)
    {
        byte[] encryptedData = Convert.FromBase64String(encryptedBase64);
        byte[] key = Convert.FromBase64String(base64Key);

        using (TripleDES tdes = TripleDES.Create())
        {
            tdes.Key = key;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;

            using (ICryptoTransform decryptor = tdes.CreateDecryptor())
            {
                byte[] decrypted = decryptor.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
                return Encoding.UTF8.GetString(decrypted);
            }
        }
    }
}